package com.ruoyi.security.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.security.domain.InspectionLocation;
import com.ruoyi.security.service.IInspectionLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 巡检地点Controller
 *
 * @author cjie
 * @date 2022-04-14
 */
@Api(tags = " 巡检地点")
@RestController
@RequestMapping("/inspectionLocation")
public class InspectionLocationController extends BaseController {
    @Autowired
    private IInspectionLocationService inspectionLocationService;

    /**
     * 查询巡检地点列表
     */
    @ApiOperation(value="查询巡检地点列表", notes="查询巡检地点列表")
    @PreAuthorize(hasPermi = "security:inspectionLocation:list")
    @GetMapping("/list")
    public TableDataInfo list(InspectionLocation inspectionLocation) {
        startPage();
        List<InspectionLocation> list = inspectionLocationService.selectInspectionLocationList(inspectionLocation);
        return getDataTable(list);
    }

    /**
     * 导出巡检地点列表
     */
    @ApiOperation(value="导出巡检地点列表", notes="导出巡检地点列表")
    @PreAuthorize(hasPermi = "security:inspectionLocation:export")
    @Log(title = "巡检地点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionLocation inspectionLocation) throws IOException {
        List<InspectionLocation> list = inspectionLocationService.selectInspectionLocationList(inspectionLocation);
        ExcelUtil<InspectionLocation> util = new ExcelUtil<InspectionLocation>(InspectionLocation.class);
        util.exportExcel(response, list, "巡检地点数据");
    }
    /**
     * 获取巡检地点详细信息
     */
    @ApiOperation(value="获取巡检地点详细信息", notes="获取巡检地点详细信息")
    @PreAuthorize(hasPermi = "security:inspectionLocation:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(inspectionLocationService.selectInspectionLocationById(id));
    }

    /**
     * 根据巡检地点查询
     */
    @ApiOperation(value="小程序获取巡检地点表单", notes="小程序获取巡检地点表单")
    @PreAuthorize(hasPermi = "security:inspectionLocation:query")
    @GetMapping(value = "/wx/{type}/{qrCode}")
    public AjaxResult getFormInfo(@PathVariable("type") String type,@PathVariable("qrCode") String qrCode) {
        return AjaxResult.success(inspectionLocationService.selectInspectionLocationByQRCoode(type, qrCode));
    }


    /**
     * 新增巡检地点
     */
    @ApiOperation(value="新增巡检地点", notes="新增巡检地点")
    @PreAuthorize(hasPermi = "security:inspectionLocation:add")
    @Log(title = "巡检地点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionLocation inspectionLocation) {
        return toAjax(inspectionLocationService.insertInspectionLocation(inspectionLocation));
    }

    /**
     * 修改巡检地点
     */
    @ApiOperation(value="修改巡检地点", notes="修改巡检地点")
    @PreAuthorize(hasPermi = "security:inspectionLocation:edit")
    @Log(title = "巡检地点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionLocation inspectionLocation) {
        return toAjax(inspectionLocationService.updateInspectionLocation(inspectionLocation));
    }

    /**
     * 删除巡检地点
     */
    @ApiOperation(value="删除巡检地点", notes="删除巡检地点")
    @ApiImplicitParam(name = "ids", value = "巡检地点ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:inspectionLocation:remove")
    @Log(title = "巡检地点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(inspectionLocationService.deleteInspectionLocationByIds(ids));
    }
}
